@inherits BulmaComponentBase
@namespace BulmaRazor.Components
@* @inject BulmaRazorJsInterop JsInterop *@

<ul @attributes="Attributes" class="@classes">
    <CascadingValue Value="this">
        @ChildContent
    </CascadingValue>
</ul>

@code {


    string classes => CssBuilder.Default("steps")
        .AddClassFromAttributes(Attributes)
        .AddClass("is-small", IsSmall)
        .AddClass("is-medium", IsMedium)
        .AddClass("is-large", IsLarge)
        .AddClass("is-thin", IsThin)
        .AddClass("is-narrow", IsNarrow)
        .AddClass("is-centered", IsCentered)
        .AddClass("is-right", IsRight)
        .AddClass("is-bottom",IsBottom)
        .AddClass("is-vertical", IsVertical)
        .AddClass("is-horizontal", IsHorizontal)
        .AddClass("is-short", IsShort)
        .AddClass("is-hollow", IsHollow)
        .AddClass("is-dashed", IsDashed)
        .AddClass("has-gaps", HasGaps)
        .AddClass("is-balanced", IsBalanced && !HasContentCentered)
        .AddClass("has-content-centered", HasContentCentered)
        .AddClass("has-content-above", HasContentAbove)
        .Build();


    /// <summary>
    /// 小尺寸
    /// </summary>
    [Parameter]
    public bool IsSmall { get; set; }

    /// <summary>
    /// 中尺寸
    /// </summary>
    [Parameter]
    public bool IsMedium { get; set; }


    /// <summary>
    /// 大尺寸
    /// </summary>
    [Parameter]
    public bool IsLarge { get; set; }

    /// <summary>
    /// 瘦样式
    /// </summary>
    [Parameter]
    public bool IsThin { get; set; }


    /// <summary>
    /// 狭窄
    /// </summary>
    [Parameter]
    public bool IsNarrow { get; set; }

    /// <summary>
    /// 居中
    /// </summary>
    [Parameter]
    public bool IsCentered { get; set; }


    /// <summary>
    /// 靠右
    /// </summary>
    [Parameter]
    public bool IsRight { get; set; }

    /// <summary>
    /// 靠下
    /// </summary>
    [Parameter]
    public bool IsBottom { get; set; }

    
    
    /// <summary>
    /// 是否垂直
    /// </summary>
    [Parameter]
    public bool IsVertical { get; set; }


    /// <summary>
    /// 是否水平
    /// </summary>
    [Parameter]
    public bool IsHorizontal { get; set; }

    /// <summary>
    /// 短样式
    /// </summary>
    [Parameter]
    public bool IsShort { get; set; }


    /// <summary>
    /// //是否空心
    /// </summary>
    [Parameter]
    public bool IsHollow { get; set; }


    /// <summary>
    /// 是否虚线
    /// </summary>
    [Parameter]
    public bool IsDashed { get; set; }

    /// <summary>
    /// 是否间隙
    /// </summary>
    [Parameter]
    public bool HasGaps { get; set; }


    /// <summary>
    /// 子内容
    /// </summary>
    [Parameter]
    public RenderFragment ChildContent { get; set; }


    /// <summary>
    /// 左右平均显示
    /// </summary>
    [Parameter]
    public bool IsBalanced { get; set; }

    /// <summary>
    /// 内容在中间
    /// </summary>
    [Parameter]
    public bool HasContentCentered { get; set; }


    /// <summary>
    /// 内容在上部
    /// </summary>
    [Parameter]
    public bool HasContentAbove { get; set; }


    /// <summary>
    /// 激活索引
    /// </summary>
    [Parameter]
    public int Active { get; set; }

    private List<StepsSegment> Segments = new();

    internal void AddSegment(StepsSegment segment)
    {
        segment.IsActive = Segments.Count == Active;
        Segments.Add(segment);
    }


    /// <summary>
    /// 设置参数
    /// </summary>
    /// <param name="parameters"></param>
    /// <returns></returns>
    public override async Task SetParametersAsync(ParameterView parameters)
    {
        await base.SetParametersAsync(parameters);
        for (int i = 0; i < Segments.Count; i++)
        {
            Segments[i].IsActive = i == Active;
        }
    }
}